from pylab import *

#evec = loadtxt('JLA_WMAP9_MP_vecs.txt')
evec = loadtxt('WFIRST_JLA_WMAP9_SP_vecs.txt')
#evec = loadtxt('JLA_WMAP9_vecs.txt')

frac1 = []
frac2 = []
frac3 = []
frac4 = []
frac5 = []
frac6 = []

for i in range(1,101):
    w = loadtxt('EoS/eos_'+str(i)+'.txt')
    dw= w[:,0]+1
    dw /= norm(dw)
    f0 = matmul(dw,evec[0,:])
    f1 = matmul(dw,evec[1,:])
    f2 = matmul(dw,evec[2,:])
    f3 = matmul(dw,evec[3,:])
    f4 = matmul(dw,evec[4,:])
    f5 = matmul(dw,evec[5,:])
    
    frac1.append( abs(f0) )
    frac2.append( (f1**2 + f0**2)**0.5 )
    frac3.append( (f2**2 + f1**2 + f0**2)**0.5 )
    frac4.append( (f3**2 + f2**2 + f1**2 + f0**2)**0.5 )
    frac5.append( (f4**2 + f3**2 + f2**2 + f1**2 + f0**2)**0.5 )
    frac6.append( (f5**2 + f4**2 + f3**2 + f2**2 + f1**2 + f0**2)**0.5 )

frac1 = array(frac1)
frac2 = array(frac2)
frac3 = array(frac3)
frac4 = array(frac4)
frac5 = array(frac5)
frac6 = array(frac6)

frac_threshold = 0.8

f1 = sum(frac1>frac_threshold)/100.
f2 = sum(frac2>frac_threshold)/100.
f3 = sum(frac3>frac_threshold)/100.
f4 = sum(frac4>frac_threshold)/100.
f5 = sum(frac5>frac_threshold)/100.
f6 = sum(frac6>frac_threshold)/100.

alpha = 0.75

figure(figsize=(6,4))

#hist(frac1, bins=15, normed=True, label=r'1')
#hist(frac2, bins=15, normed=True, label=r'2')
hist(frac3, bins=15, normed=True, label=r'1--3 WPCs, $frac(S>'+str(frac_threshold)+')='+str(round(f3,4))+'$',alpha=alpha)
hist(frac4, bins=15, normed=True, label=r'1--4 WPCs, $frac(S>'+str(frac_threshold)+')='+str(round(f4,4))+'$',alpha=alpha)
hist(frac5, bins=15, normed=True, label=r'1--5 WPCs, $frac(S>'+str(frac_threshold)+')='+str(round(f5,4))+'$',alpha=alpha)
hist(frac6, bins=15, normed=True, label=r'1--6 WPCs, $frac(S>'+str(frac_threshold)+')='+str(round(f6,4))+'$',alpha=alpha)

legend(loc='best',frameon=False,fontsize=11)

xlabel(r'Similarity')

text(0.15,5,r'similarity_threshold='+str(frac_threshold),fontsize=11)

savefig('dist_of_similarity_WJW.pdf')

#show()
